Skip to main content

Querying API End-points

Certain things need to be kept in mind while querying the API end-points of our application.

Log-in and Base64 Encoding

Instead of sending JSON Strings, we shall first encode them to Base64 format and then send them. To illustrate the same, let us first try to log in to our application. To do so :

  1. Open Postman and create a new POST request.
  2. Set the URL as localhost:8081/api/login
  3. Switch to the Headers tab and add a Content-Type header with the value as application/x-www-form-urlencoded.

UML

  1. Now move over to the Body tab and select x-www-form-urlencoded. Add a key named resource. To get the corresponding value, visit https://www.base64encode.org/ and add the login details there in JSON format :
{
"email_id" : "super@user",
"password" : "password"
}

Use the encoded value as the value for the resource field. This encoding step is common to all POST routes which have the resource key in the body.

UML

  1. Send the request. You should receive a response which looks as follows :
{
"resource":
[{
"id":"baf2ab61-20ab-40fc-81a4-29104ff29f2a-20",
"email_id":"super@user",
"password":"password",
"session_id":"b5d79374-a5cf-4c6a-b7ff-edbe69108c27-25",
"type":"SYSTEM_USER"
}],
"errCode":0,
"message" : "Success"
}

The session_id will be used in authentication for the other routes.

Adding a playground

Create a new JSON object which describes a playground as follows :

{ 
"name" : "IIITB_Cricket",
"latitude" : 30,
"longitude" : 95,
"total_capacity" : 100
}

Now encode the above JSON file in the Base64 format and add it as the value for the resource field in the body of a new POST request. The URL should be set as localhost:8081/api/playground while the same headers should be used as described in the log in request.

Also add the session_id key to the body of the request with the value being set as the session_id obtained during login.

UML

Upon firing the request, we get the following message upon success :

{
"resource" : [{
"id":"aa61f1d2-07e9-44d2-8e6b-2710ec1a5746-32",
"g_created_by_id":"super@user",
"g_created_by_name":"Super User",
"g_creation_time":1718344805826,
"g_soft_delete":"N",
"name":"IIITB_Cricket",
"latitude":30.0,
"longitude":95.0,
"total_capacity":100
}],
"errCode" : 0,
"message" : "Success"
}

Fetching all playgrounds

We can verify that the create operation was successful, by querying for all playgrounds. To do so, we fire a GET request to localhost:8081/api/playground with the appropriate headers, session_id and queryId = GET_ALL.

UML

If the operation was successful, we can expect the following response :

{
"resource":[{
"id":"aa61f1d2-07e9-44d2-8e6b-2710ec1a5746-32",
"g_created_by_id":"super@user",
"g_created_by_name":"Super User",
"g_creation_time":1718344805826,
"g_soft_delete":"N",
"name":"IIITB_Cricket",
"latitude":30.0,
"longitude":95.0,
"total_capacity":100
}],
"errCode":0,
"message":"Success"
}

Voila! We got our first application up-and-running using the RASP-Platform !!!